<?php
class HouseAction extends BaseAction
{

    public function index()
    {
        if (!$this->isPost())
        {
            $result = M("area")->select();
            $this->assign("area", $result);
            //地铁站
            $ditie = M("subway")->select();
            $this->assign("ditie", $ditie);
            //租赁方式
            $rent = M("rent")->select();
            $this->assign("rent", $rent);
            //房源类型
            $type = M("type")->select();
            $this->assign("type", $type);
            //商圈
            $district = M("district")->select();
            $this->assign("district", $district);
            $this->display();
        }
        else
        {
            /* if(!isset($_SESSION['userinfo']['v_id']) || empty($_SESSION['userinfo']['v_id']))
        	{
        		self::show_msg('请先登录');
        	}  */
            if (isset($_POST['housetype']))
            {
                if ($_POST['housetype'] == 1)
                {
                    $pre = 'b_';
                    $mod = M('bieshu');
                }
                if ($_POST['housetype'] == 2)
                {
                    $pre = 'x_';
                    $mod = M('xiezilou');
                }
                if ($_POST['housetype'] == 3)
                {
                    $pre = 's_';
                    $mod = M('shangpu');
                }
                if ($_POST['housetype'] == 4)
                {
                    $pre = 'g_';
                    $mod = M('gongyu');
                }
                if ($_POST['housetype'] == 5)
                {
                    $pre = 'z_';
                    $mod = M('zheng');
                }
                if ($_POST['housetype'] == 6)
                {
                    $pre = 'y_';
                    $mod = M('yezhu');
                }
            }
            else
            {
                self::show_msg('请选择房源性质');
            }
            //获得图片
            $newname = ROOT_DIR . DS . 'Public/Upload/';
            $pic = $_FILES['img'];
            import('ORG.NET.UploadFile');
            $U = new UploadFile('', '', '', $newname, 'uniqid');
            $name = $U->uploadOne($pic, $newname);
            //楼盘名字
            $data[$pre.'name'] = $_POST['name'];
            //楼盘图片
            $data[$pre.'img'] = $name[0]['savename'];
            //楼盘位置
            $data[$pre.'location'] = $_POST['location'];
            //所 属  区
            $data[$pre.'quyu'] = $_POST['quyu'];
            //所属商圈
            $data[$pre.'district'] = $_POST['district'];
            //所属地铁线
            $data[$pre.'subway'] = $_POST['subway'];
            //所属地铁站
            $data[$pre.'subway_station'] = $_POST['subway_station'];
            //租赁方式
            $data['s_zulin'] = $_POST['zulin'];
            //房源位置
            $data[$pre.'location'] = $_POST['location'];
            //开发商
            $data[$pre.'developers'] = $_POST['developers'];
            //单价
            $data[$pre.'sell'] = $_POST['sell'];
            //总价
            $data[$pre.'zongjia'] = $_POST['zongjia'];
            //日租金
            $data[$pre.'d_rent'] = $_POST['d_rent'];
            //月租金
            $data[$pre.'m_rent'] = $_POST['m_rent'];
            //建筑面积
            $data[$pre.'build_area'] = $_POST['build_area'];
            //使用面积
            $data[$pre.'use_area'] = $_POST['use_area'];
            //详细标题
            $data[$pre.'title'] = $_POST['title'];
            //所在楼层
            $data[$pre.'floor'] = $_POST['floor'];
            //装修状况
            $data[$pre.'decoration'] = $_POST['decoration'];
            //楼盘等级
            $data[$pre.'rating'] = $_POST['rating'];
            //支付方式
            $data[$pre.'pay_type'] = $_POST['pay_type'];
            //配套设施
            $data[$pre.'supproting'] = $_POST['supproting'];
            //房源描述
            $data[$pre.'description_info'] = $_POST['description_info'];
            //图片描述
            $data[$pre.'description_img'] = $_POST['description_img'];
            //地图交通
            $data[$pre.'description_map'] = $_POST['description_map'];
            //楼盘简介
            $data[$pre.'summary_info'] = $_POST['summary_info'];
            //周边设施
            $data[$pre.'nearby'] = $_POST['nearby'];
            //所属经纪人
            $data[$pre.'broker'] = $_SESSION['userinfo']['v_id'];
            $data['time'] = time();
            
            $result = $mod->data($data)->add();
            
            if ($result)
            {
                $this->assign("jumpUrl", "__URL__/index");
                $this->assign("waitSecond", 3);
                $this->success("添加成功！！！");
            }
            else
            {
                $this->assign("jumpUrl", "__URL__/index");
                $this->assign("waitSecond", 3);
                $this->error("添加失败！！！");
            }
        }
    }

    static private function show_msg($title)
    {
        if ($title == '请先登录')
        {
            echo "
    		<script>
    		alert('请先登录');
    		window.location.href = '/index.php/login';
    		</script>
    		";
            exit('aa');
        }
        echo "
    		<script>
    			alert('" . $title . "');
    			window.location.href = '/index.php/house';
    		</script>
    	";
        exit();
    }
}

?>

